<template>
  <div v-loading="loading" class="parentStyle">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row :gutter="20">
        <el-col ref="spanMain" :span="16">
          <div class="area-header">
            <span class="area-header-title">{{ $t('公示公告') }}</span>
          </div>
          <el-col :span="12">
            <el-form-item :label="$t('基金名称')" prop="fundId">
              <el-select v-model="form.fundId" :disabled="callInitStatus" filterable clearable :placeholder="$t('基金名称')" @change="dataChange($event); form.type = undefined; form.period = undefined">
                <el-option
                  v-for="item in fundBaseList"
                  :key="item.id"
                  :label="item.fundName"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('公告类型')" prop="type">
              <el-select v-model="form.type" :disabled="callInitStatus" clearable :placeholder="$t('公告类型')" @change="changeType(form.type)">
                <el-option
                  v-for="dict in lpTemplate"
                  :key="dict.id"
                  :label="$t(dict.name)"
                  :value="dict.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-if="displayNone.period" :span="12">
            <el-form-item :label="$t('分配期次')" prop="period">
              <el-select v-model="form.period" clearable :disabled="callInitStatus" :placeholder="$t('分配期次')" @change="showFpInvestor($event)">
                <el-option
                  v-for="dict in allocationPeriodDict"
                  :key="dict.id"
                  :label="$t(dict.name)"
                  :value="dict.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-if="displayNone.fundScale" :span="12">
            <el-form-item :label="$t('基金规模') + $t('金额单位')" prop="fundScale">
              <Money v-model="form.fundScale" unit="w" disabled :placeholder="$t('基金规模')" />
            </el-form-item>
          </el-col>
          <el-col v-if="displayNone.callPeriod" :span="12">
            <el-form-item :label="$t('Call款期次')" prop="callPeriod">
              <el-select v-model="form.callPeriod" :disabled="callInitStatus" clearable :placeholder="$t('Call款期次')" @change="changeCallPeriod()">
                <el-option
                  v-for="dict in callPeriodOptions"
                  :key="dict.id"
                  :label="$t(dict.callPeriod)"
                  :value="dict.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-if="displayNone.callProp" :span="12">
            <el-form-item :label="$t('Call款比例(%)')" prop="callProp">
              <Ratio v-model="form.callProp" disabled :precision="2" :controls="false" :placeholder="$t('Call款比例')" @blur="callCalculation" />
            </el-form-item>
          </el-col>
          <el-col v-if="displayNone.callMoney" :span="12">
            <el-form-item :label="$t('Call款金额') + $t('金额单位')" prop="callMoney">
              <Money v-model="form.callMoney" unit="w" disabled :placeholder="$t('Call款金额')" />
            </el-form-item>
          </el-col>
          <el-col v-if="displayNone.subscribedAmount" :span="12">
            <el-form-item :label="$t('认缴金额') + $t('金额单位')" prop="subscribedAmount">
              <Money v-model="form.subscribedAmount" unit="w" :placeholder="$t('认缴金额')" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('是否发送邮件')" prop="sendEmailStatus">
              <el-radio v-model="form.sendEmailStatus" label="true">{{ $t('发送') }}</el-radio>
              <el-radio v-model="form.sendEmailStatus" label="false">{{ $t('不发送') }}</el-radio>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item :label="$t('公告标题')" prop="title">
              <el-input v-model="form.title" maxlength="1000" :placeholder="$t('公告标题')" show-word-limit @focus="blurEvent($event, 'title')" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item :label="$t('公告内容')" prop="context">
              <EditorTxt ref="editorText" :key="form.id" v-model="form.context" :height="400" :placeholder="$t('公告内容')" @focus="blurEvent($event, 'context')" />
            </el-form-item>
          </el-col>
        </el-col>
        <el-col :span="8">
          <div class="area-header">
            <span class="area-header-title">{{ $t('随函附件') }}</span>
          </div>
          <div v-loading="uploadLoading">
            <el-table :element-loading-text="$t('上传中...')" :data.sync="form.fileList" border class="nowrapTable formTable printArea" style="height: 200px;">
              <el-table-column :label="$t('附件名称')" align="left" prop="name" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                  <el-link type="primary" :underline="false" @click="onlinePreview(scope.row)">{{ scope.row.name }}</el-link>
                </template>
              </el-table-column>
              <el-table-column :label="$t('操作')" :show-overflow-tooltip="true" width="50">
                <template slot-scope="scope">
                  <el-button
                    v-hasPermi="['lp:LpPublicBulletin:edit']"
                    size="small"
                    type="text"
                    icon="el-icon-delete"
                    @click="delFile(scope.row, scope.$index)"
                  />
                </template>
              </el-table-column>
            </el-table>
            <div v-if="showSaveBtn" v-hasPermi="['lp:LpPublicBulletin:edit']" class="tol">
              <single :data-type="'lp_public_bulletin'" :upload-style="uploadStyle" @appendData="appendData" @okPostUploadHook="okPostUploadHook" />
            </div>
          </div>
          <div class="area-header mt15">
            <span class="area-header-title">{{ $t('关键字列表') }}</span>
          </div>
          <el-table :data="keywordList" border max-height="500" style="border-bottom: 1px solid #dfe6ec;">
            <el-table-column :label="$t('名称')" align="center" prop="dictLabel" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                【{{ scope.row.dictLabel }}】
              </template>
            </el-table-column>
            <el-table-column :label="$t('操作')" width="50">
              <template slot-scope="scope">
                <el-button
                  v-hasPermi="['lp:LpPublicBulletin:edit']"
                  size="small"
                  type="text"
                  :disabled="!optionalKeywords.includes(scope.row.dictValue)"
                  @click="addKeyWork(scope.row.dictLabel)"
                >{{ $t('插入') }}</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
        <el-col v-if="showLpList">
          <div class="area-header">
            <span class="area-header-title" style="padding-right: 0;">{{ $t('出资人') }}</span>
            <el-tooltip placement="top">
              <div slot="content">
                {{ $t('出资人为个人或机构时, 则带出该出资人下的联系人列表信息') }}
                <br>
                {{ $t('出资人为基金管理人等, 则带出基金出资人信息中的邮箱信息') }}
              </div>
              <i class="el-icon-question" />
            </el-tooltip>
            <div style="float: right;">
              <el-button
                v-if="callInitStatus && showSaveBtn && !isEmpty(form.callPeriod)"
                size="mini"
                type="success"
                @click="generateExclDoc()"
              >{{ $t('Call款文档') }}</el-button>
              <el-button
                v-if="callInitStatus && showSaveBtn && !isEmpty(form.period)"
                size="mini"
                type="success"
                @click="generateFpExclDoc()"
              >{{ $t('分配文档') }}</el-button>
              <el-button
                v-if="form.lpBaseList !== undefined && form.lpBaseList !== null && form.lpBaseList.length > 0 && showSaveBtn"
                size="mini"
                type="warning"
                @click="uploadAuto"
              >{{ $t('批量上传') }}</el-button>
            </div>
          </div>
          <el-table v-loading="LpBulletinInvestorLoading" :element-loading-text="LpBulletinInvestorText" :data.sync="form.lpBaseList" border class="nowrapTable formTable printArea">
            <el-table-column :label="$t('出资人名称')" align="center" prop="userName" :show-overflow-tooltip="true" min-width="180" />
            <el-table-column :label="$t('类型')" align="center" prop="lpType" :show-overflow-tooltip="true" min-width="100">
              <template slot-scope="scope">
                <span v-if="scope.row.lpType === 'intention'">{{ $t('意向出资人') }}</span>
                <span v-if="scope.row.lpType === 'investor'">{{ $t('在投出资人') }}</span>
              </template>
            </el-table-column>
            <el-table-column :label="$t('主送邮箱')" align="center" prop="lpEmail" :show-overflow-tooltip="true" min-width="150">
              <template slot-scope="scope">
                <div :style="{ 'white-space': isEmpty(scope.row.lpEmail) ? 'unset' : 'pre-wrap' }">
                  <el-tag
                    v-for="tag in splitEmail(scope.row, 'lpEmail')"
                    :key="tag + scope.$index"
                    closable
                    size="mini"
                    style="margin: 0 2px 0 2px;"
                    :disable-transitions="false"
                    @close="handleClose(scope.row, scope.$index, tag, 'to')"
                  >
                    {{ tag }}
                  </el-tag>
                  <el-select
                    v-if="lpEmailVisible[scope.row.lpId]"
                    v-model="scope.row.emailValue"
                    filterable
                    clearable
                    class="search-input"
                    size="mini"
                    @focus="querySearch(scope.row.emailValue, scope.$index, 'lpEmail', scope.row.lpId)"
                    @keyup.enter.native="handleEmailConfirm(scope.row, $event)"
                    @blur="handleEmailConfirm(scope.row, $event)"
                  >
                    <el-option
                      v-for="(item, index) in fileFormatArr[scope.row.lpId]"
                      :key="index"
                      :value="item.value"
                      :label="item.email"
                    />
                  </el-select>
                  <div v-else>
                    <el-button style="height: 20px;" size="mini" @click="showEmailInput(scope.row)">
                      <i class="el-icon-plus" style="margin-top: -5px;position: absolute;margin-left: -5px;" />
                    </el-button>
                  </div>
                </div>
              </template>
            </el-table-column>
            <el-table-column :label="$t('抄送邮箱')" align="center" prop="lpEmailCc" :show-overflow-tooltip="true" min-width="150">
              <template slot-scope="scope">
                <div :style="{ 'white-space': isEmpty(scope.row.lpEmailCc) ? 'unset' : 'pre-wrap' }">
                  <el-tag
                    v-for="tag in splitEmail(scope.row, 'lpEmailCc')"
                    :key="tag + scope.$index"
                    closable
                    size="mini"
                    style="margin: 0 2px 0 2px;"
                    :disable-transitions="false"
                    @close="handleClose(scope.row, scope.$index, tag, 'cc')"
                  >
                    {{ tag }}
                  </el-tag>
                  <el-select
                    v-if="lpEmailCcVisible[scope.row.lpId]"
                    v-model="scope.row.emailCcValue"
                    filterable
                    clearable
                    class="search-input"
                    size="mini"
                    @focus="querySearch(scope.row.emailCcValue, scope.$index, 'lpCcEmail', scope.row.lpId)"
                    @keyup.enter.native="handleEmailCcConfirm(scope.row, $event)"
                    @blur="handleEmailCcConfirm(scope.row, $event)"
                  >
                    <el-option
                      v-for="(item, index) in fileFormatArr[scope.row.lpId]"
                      :key="index"
                      :value="item.value"
                      :label="item.email"
                    />
                  </el-select>
                  <div v-else>
                    <el-button style="height: 20px;" size="mini" @click="showEmailCcInput(scope.row)">
                      <i class="el-icon-plus" style="margin-top: -5px;position: absolute;margin-left: -5px;" />
                    </el-button>
                  </div>
                </div>
              </template>
            </el-table-column>
            <el-table-column v-if="templateType === 'JKTZ'" :label="$t('认缴金额') + $t('金额单位')" align="center" prop="subscribedAmount" :show-overflow-tooltip="true" width="110">
              <template slot-scope="scope">
                {{ moneyFormat(scope.row.subscribedAmount, 'w') }}
              </template>
            </el-table-column>
            <el-table-column v-if="templateType === 'JKTZ'" :label="$t('Call款金额') + $t('金额单位')" align="center" prop="callMoney" :show-overflow-tooltip="true" width="110">
              <template slot-scope="scope">
                <!-- <Money v-model="scope.row.callMoney" unit="w" :placeholder="$t('Call金额')" /> -->
                {{ moneyFormat(scope.row.callMoney, 'w') }}
              </template>
            </el-table-column>
            <el-table-column v-if="templateType === 'JKTZ'" :label="$t('Call款时间')" align="center" prop="callTime" :show-overflow-tooltip="true" width="110">
              <template slot-scope="scope">
                <!-- <DatePicker v-model="scope.row.callTime" :placeholder="$t('Call款时间')" /> -->
                {{ parseTime(scope.row.callTime) }}
              </template>
            </el-table-column>
            <el-table-column :label="$t('附件')" align="center" :show-overflow-tooltip="false" width="180">
              <template slot-scope="scope">
                <div v-for="item in scope.row.fileList" :key="item.id">
                  <thumbnail :file-data="item" />
                </div>
              </template>
            </el-table-column>
            <el-table-column v-if="showSaveBtn" :label="$t('操作')" align="center" style="padding: 0;" width="235">
              <template slot-scope="scope">
                <el-button
                  v-hasPermi="['lp:LpPublicBulletin:edit']"
                  size="small"
                  type="text"
                  icon="el-icon-files"
                  @click="viewInvestorInfo(scope.row, scope.$index)"
                >{{ $t('预览') }}</el-button>
                <el-button
                  v-if="!callMoneyUseProcess"
                  v-hasPermi="['lp:LpPublicBulletin:edit']"
                  size="small"
                  type="text"
                  icon="el-icon-delete"
                  @click="delLpBase(scope.row, scope.$index)"
                >{{ $t('删除') }}</el-button>
                <el-button
                  v-hasPermi="['lp:LpPublicBulletin:edit']"
                  size="small"
                  type="text"
                  icon="el-icon-files"
                  @click="addFiles(scope.row, scope.$index)"
                >{{ $t('附件') }}</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: center;">
      <el-button @click="cancel">{{ $t("取消") }}</el-button>
      <el-button v-if="showSaveBtn && !callMoneyUseProcess" v-hasPermi="['lp:LpPublicBulletin:edit']" type="primary" @click="openInvestList">{{ $t("选择LP") }}</el-button>
      <el-button v-if="showSaveBtn" v-hasPermi="['lp:LpPublicBulletin:edit']" type="primary" @click="saveForm">{{ $t("保存") }}</el-button>
      <el-button v-if="!callMoneyUseProcess && showSaveBtn" v-hasPermi="['lp:LpPublicBulletin:edit']" type="primary" @click="saveAndSubmitForm">{{ $t("保存并提交至复核") }}</el-button>
    </div>
    <!-- 预览 -->
    <OnlinePreview ref="OnlinePreview" />
    <!-- 出资人列表 -->
    <el-dialog :title="title" :visible.sync="lpInvestorOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="folderOpen" append-to-body>
      <listOfFundersInTheFund ref="listOfFundersInTheFund" @choiceBaseList="choiceBaseList" @lpBaseClean="lpBaseClean" />
    </el-dialog>

    <!-- 自动未出资人分配文件 -->
    <el-dialog :title="$t('附件分配')" :visible.sync="autoUploadOpen" width="750px" style="height: 550px; margin: auto" :close-on-click-modal="false" :destroy-on-close="true" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <autoUpload ref="autoUpload" :lp-list="form.lpBaseList" @autoUploadFileEnd="autoUploadFileEnd" />
    </el-dialog>

    <!-- 添加附件 -->
    <el-dialog :title="$t('出资人随函附件')" :visible.sync="addFilesOpen" width="50%" style="height: 80%; margin: auto" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <template>
        <div v-loading="fileLoading">
          <div>
            <el-table :data="investorFileList" border class="nowrapTable formTable">
              <el-table-column :label="$t('文件名称')" align="center" prop="fileName">
                <template slot-scope="scope">
                  <el-link type="primary" :underline="false" @click="onlinePreview(scope.row)">{{ scope.row.fileName || scope.row.name }}</el-link>
                </template>
              </el-table-column>
              <el-table-column :label="$t('操作')" align="center" width="60px">
                <template slot-scope="scope">
                  <el-button size="small" type="text" icon="el-icon-delete" @click="delRow(scope.$index)" />
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div slot="footer" class="dialog-footer" style="text-align: right;">
            <el-upload
              name="files"
              :action="uploadUrl"
              :headers="headers"
              :data="uploadData"
              :auto-upload="true"
              :show-file-list="false"
              :on-success="onSuccess"
              :on-error="onError"
              :on-progress="onProgress"
              :file-list="investorFileList"
              style="float: left;"
              class="upload-demo"
            >
              <el-button size="small" type="warning" style="margin-right: 15px;">{{ $t('点击上传') }}</el-button>
            </el-upload>
            <el-button type="primary" size="small" style="float: left;margin-right: 15px;" @click="addFilesOpen = false">{{ $t("完成") }}</el-button>
          </div>
        </div>
      </template>
    </el-dialog>

    <!-- 预览公告 -->
    <el-dialog :visible.sync="viewInvestorInfoOpen" :title="$t('公告内容预览')" :destroy-on-close="true" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body width="60%" style="margin-top: 15vh !important; height: 600px">
      <div v-loading="viewInvestorInfoLoading" style="height: 440px;overflow: auto;" v-html="viewHtmlInfo" />
    </el-dialog>
  </div>
</template>

<script>
import listOfFundersInTheFund from '@/views/fund/lpBase/lp/listOfFundersInTheFund.vue'
import single from '@/components/File/Upload/single.vue'
import EditorTxt from '@/components/Tinymce'
import thumbnail from '@/components/File/OnlinePreview/thumbnail.vue'
import autoUpload from '@/views/fund/lpBase/lp/autoUpload.vue'
import {
  saveLpPublicBulletin,
  getLpPublicBulletin,
  updateReviewStatus,
  modifyShowStatus,
  viewInvestorInfo
} from '@/api/fund/lpBase/lp/affiche/affiche.js'
import { getLpAnnouncementTemplate, listTemplateAndBusinessId } from '@/api/fund/lpBase/lp/affiche/afficheListTemplate'
import { listFundFpMainAll } from '@/api/fund/fp/fundFpMain.js'
import { listFundInvestorAll } from '@/api/fund/investor/fundInvestor.js'
import { delLpBulletinInvestor } from '@/api/fund/lpBase/lp/affiche/lpBulletinInvestor.js'
import { delFile } from '@/api/file/fileBase.js'
import { listFundCallMoneyAll, getFundCallMoney, callFundsBoundToTheFund, fundFpBoundToTheFund } from '@/api/fund/callmoney/fundCallMoney.js'
import { findLpBaseList, showFpInvestor } from '@/api/fund/lpBase/lpBase.js'
import { config } from '@/utils'
import { getToken } from '@/utils/auth'
import { findFundFof } from '@/api/fund/fundBase'
import { listDealContacts } from '@/api/deal/contact/contactsPerson'
export default {
  components: {
    EditorTxt,
    single,
    listOfFundersInTheFund,
    thumbnail,
    autoUpload
  },
  props: {
    // 是否从基金call款中发起的当前页面
    callInitStatus: {
      type: Boolean,
      default: () => false
    },
    // callInitStatus 为true 时该字段必填
    callMoneyUseProcess: {
      type: Boolean,
      default: () => false
    },
    showSaveBtn: {
      type: Boolean,
      default: () => true
    },
    // 当前页面的父页面是什么通知类型, callMoney/fundFpMain
    parentBusinessType: {
      type: String,
      default: () => ''
    }
  },
  data() {
    return {
      // 表单参数
      form: {},
      // 当前模板类型属于那种
      templateType: '',
      isTitleSetKeWord: false,
      isSetKeyWordType: '',
      // 遮罩层
      loading: false,
      followHeight: 500,
      // 表单校验
      rules: {
        fundId: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        type: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        callPeriod: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        period: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        fundScale: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        callProp: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        callMoney: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        subscribedAmount: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        title: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        context: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        sendEmailStatus: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }]
      },
      fundBaseList: [],
      // 关键字
      keywordList: [],
      lpTemplate: [],
      // 字段隐藏
      displayNone: {
        // 分配批次
        period: false,
        // 基金规模
        fundScale: false,
        // Call款比例
        callProp: false,
        // Call款金额
        callMoney: false,
        // 认缴金额
        subscribedAmount: false
      },
      // 上传
      uploadStyle: 'border-radius: 3px; border: 1px solid rgba(112, 116, 122, 0.2);',
      uploadLoading: false,
      allocationPeriodDict: [],
      // 出资人
      lpInvestorOpen: false,
      title: '',
      LpBulletinInvestorLoading: false,
      LpBulletinInvestorText: '',
      // 可选关键字
      optionalKeywords: [],
      // Call款下拉
      callPeriodOptions: [],
      // 当前基金下的LPCall款出资人( 选择LP 按钮查出来的是啥这里就是啥)
      callFunder: [],
      fileLoading: false,
      // 添加出资人附件窗口
      addFilesOpen: false,
      // 自动分配附件窗口
      autoUploadOpen: false,
      // 当前选中的出资人
      currentInvestId: undefined,
      showLpList: true,
      investorFileList: [],
      // 预览
      viewInvestorInfoOpen: false,
      viewInvestorInfoLoading: false,
      viewHtmlInfo: '',
      headers: {
        Authorization: 'Bearer ' + getToken()
      },
      uploadData: {
        dataType: 'lp_bulletin_investor'
      },
      uploadUrl: config.baseURL + '/file/fileBase/uploadVant',
      // 非Call款 非分配, 新增进入页面以下字段不可选
      defaultOptionalKey: ['CKJE', 'CKBL', 'FPPC', 'CKQC', 'CKRQ', 'FPSJ', 'SHSJZZF', 'FPBJ', 'SQSY', 'SHSY', 'SF', 'SYJKJE', 'JKJZRQ'],
      // 分配专有关键字
      fpKey: ['FPPC', 'FPSJ', 'SHSJZZF', 'FPBJ', 'SQSY', 'SHSY', 'SF'],
      // Call款专属
      callKey: ['CKJE', 'CKBL', 'CKRQ', 'CKQC', 'SYJKJE', 'JKJZRQ'],
      thisFundLpEmailArr: [],
      lpEmailVisible: [],
      lpEmailCcVisible: [],
      fileFormatArr: {}
    }
  },
  watch: {
    'form.context': {
      handler(val) {
        if (val !== null && val !== '' && val !== undefined) {
          this.$nextTick(() => {
            this.$refs['form'].validate()
          })
        }
      }
    },
    'form.callMoney': {
      handler(val) {
        if (val === undefined || val === '' || val === null || isNaN(val)) {
          this.form.callMoney = 0
        }
      }
    },
    'form.fundId': {
      handler(fundId) {
        // 加载该基金下的所有出资人
        if (fundId) {
          findLpBaseList({ fundId: fundId }).then(response => {
            this.callFunder = response.rows
          })
          this.getFundInvestorList(fundId)
        }
      }
    },
    this: {
      handler() {
        this.$nextTick(() => {
          this.followHeight = this.$refs.spanMain.$el.offsetHeight
        })
      },
      immediate: true,
      deep: true
    }
  },
  created() {
    this.getDicts('lp_poster_keywords').then(response => {
      this.keywordList = response.data
      this.keywordList.forEach(item => {
        if (!this.defaultOptionalKey.includes(item.dictValue)) {
          this.optionalKeywords.push(item.dictValue)
        }
      })
    })
    findFundFof().then(response => {
      this.fundBaseList = response.data
    })
  },
  mounted() {
  },
  methods: {
    // 初始化数据 listOfFundersInTheFund
    init(data) {
      if (data !== null && data.id !== undefined) {
        this.loading = true
        getLpPublicBulletin(data.id).then(response => {
          if (response.data === null) {
            this.loading = false
            this.$emit('notNullAfffiche', data)
          } else {
            this.form = response.data
            // 加载类型下拉
            listTemplateAndBusinessId({ businessId: this.form.fundId, businessType: this.parentBusinessType }).then(response => {
              this.lpTemplate = response.rows
              this.$forceUpdate()
              // 自动加载是那种通知模板类型
              this.autoUseTemplate(this.form.type)
              // 处理模板类型加载
              if (this.templateType === 'FPTZ') {
                this.displayNone = { period: true, fundScale: false, callProp: false, callMoney: false }
                this.getFundFpMain({ fundId: this.form.fundId })
              }
              if (this.templateType === 'JKTZ') {
                this.displayNone = { period: false, fundScale: true, callPeriod: true, callProp: true, callMoney: true }
                // 获取根据基金ID 获取Call款期次
                this.getTheCallPeriodByFundId(this.form.fundId)
              }
              // 关键字能选那些
              this.optionalKeywordsMethod()
              // 修改时 总提示必填解决方案
              // this.$refs['form'].validate()
              // 加载所有基金出资人
              this.getFundInvestorList(this.form.fundId)
              this.loading = false
            }).catch(() => {
              this.loading = false
            })
          }
        }).catch(() => {
          this.loading = false
        })
      } else {
        this.reset()
        this.getLpTemplateSelect()
      }
    },
    async getLpTemplateSelect() {
      // 获取公告类型
       await listTemplateAndBusinessId({ businessId: this.form.fundId, businessType: this.parentBusinessType }).then(response => {
         this.lpTemplate = response.rows
         this.$forceUpdate()
      })
    },
    // 根据选择的类型, 判断是用的那种通知模板
    autoUseTemplate(type) {
      this.templateType = ''
      var find = this.lpTemplate.find(obj => obj.id === type)
      if (find) {
        this.templateType = find.selected
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        fundId: undefined,
        type: undefined,
        period: undefined,
        fundScale: undefined,
        callProp: 0,
        sendEmailStatus: 'true',
        callMoney: undefined,
        subscribedAmount: undefined,
        title: undefined,
        context: undefined,
        remarks: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined,
        fileList: [],
        lpBaseList: []
      }
      this.resetForm('form')
    },
    // 取消按钮
    cancel() {
      this.$parent.$parent.formOpen = false
      this.$parent.$parent.publicityOpen = false
    },
    // 关闭form页面
    closeForm() {
      // 关闭form页面遮罩层
      this.loading = false
      // 关闭form页面
      this.$parent.$parent.formOpen = false
      // 刷新list页面
      this.$parent.$parent.publicityOpen = false
      this.$nextTick(() => {
        if (this.$parent.$parent.getList() !== undefined) {
          this.$parent.$parent.getList()
        }
      })
    },
    checkInvestEmail(value) {
      var flag = true
      if (!this.isEmpty(value)) {
        const email = value.split(';')
        if (email.length > 0) {
          email.forEach((v) => {
            var ofi = v.indexOf('@')
            if (ofi !== -1) {
              var start = v.substring(0, ofi)
              var end = v.substring(ofi + 1)
              var startNum = start.length
              var endNum = end.length
              if (startNum <= 0 || endNum <= 0) {
                flag = false
                this.msgError(this.$t('请输入有效的邮箱'))
              }
              if (this.countChar(v, '@') !== 1) {
                flag = false
                this.msgError(this.$t('请输入有效的邮箱'))
              }
            } else {
              flag = false
              this.msgError(this.$t('请输入有效的邮箱'))
            }
          })
        }
      }
      return flag
    },
    /**
     * 工具: 获取字符串中有几个指定字符
     */
    countChar(str, char) {
      let count = 0
      for (let i = 0; i < str.length; i++) {
        if (str[i] === char) {
          count++
        }
      }
      return count
    },
    setLpEmail() {
      if (!this.isEmpty(this.thisFundLpEmailArr) && this.isEmpty(this.form.id)) {
        // 给当前表单中的所有出人增加邮箱
        this.form.lpBaseList && this.form.lpBaseList.forEach((item, index) => {
          if (this.isEmpty(item.lpEmail) || this.isEmpty(item.lpEmailCc)) {
            const email = this.thisFundLpEmailArr.find(obj => obj.lpId === item.lpId)
            if (email) {
              if (!this.isEmpty(email.email)) {
                this.$set(this.form.lpBaseList[index], 'lpEmail', email.email)
                this.$set(this.form.lpBaseList[index], 'lpEmailStatus', 'newAdd')
              }
              if (!this.isEmpty(email.emailCc)) {
                this.$set(this.form.lpBaseList[index], 'lpEmailCc', email.emailCc)
                this.$set(this.form.lpBaseList[index], 'lpEmailCcStatus', 'newAdd')
              }
            }
          }
        })
      }
    },
    // 获取当前基金下所有的出资人. 目的是为了拿到他们的邮箱
    getFundInvestorList(fundId) {
      if (fundId && this.thisFundLpEmailArr.length <= 0) {
        findLpBaseList({ fundId: fundId }).then(response => {
          this.thisFundLpEmailArr = []
          response.rows && response.rows.forEach(item => {
            this.thisFundLpEmailArr.push({ lpId: item.customerId, email: item.investEmail, emailCc: item.investEmailCc })
          })
          this.setLpEmail()
        })
      }
    },
    /** 提交按钮 */
    saveForm() {
      this.submitForm(false)
    },
    saveAndSubmitForm() {
      if (this.callInitStatus) {
        var _this = this
        this.$confirm(this.$t('确认后将提交审核,是否继续?'), this.$t('提示'), {
          confirmButtonText: this.$t('是的'),
          cancelButtonText: this.$t('取消'),
          type: 'info'
        }).then(() => {
          _this.submitForm(true)
        }).catch(() => {
        })
      } else {
        this.submitForm(true)
      }
    },
    submitForm: async function(submitFlag) {
      this.$refs['form'].validate(valid => {
        var flag = true
        if (submitFlag || this.callInitStatus) {
          if (this.form.lpBaseList === null || this.form.lpBaseList === undefined || this.form.lpBaseList.length <= 0) {
            this.msgError(this.$t('请添加出资人'))
            flag = false
          }
        }
        if (valid && flag) {
          console.log('保存')
          this.loading = true
          saveLpPublicBulletin(this.form).then(async response => {
            if (response.code === 200) {
              this.form = response.data
              if (this.callInitStatus) {
                // 绑定到该基金的call款款上
                this.$emit('bindToFundCall', response.data)
                if (!this.isEmpty(this.form.callPeriod)) {
                  // call款保存公告
                  await callFundsBoundToTheFund(response.data.id, this.form.callPeriod)
                } else if (!this.isEmpty(this.form.period)) {
                  // 基金分配保存公告
                  await fundFpBoundToTheFund(response.data.id, this.form.period)
                }
                // 修改公示公的可显示状态
                await modifyShowStatus(response.data.id, this.callMoneyUseProcess ? 'N' : 'W')
              }
              // 改变审核状态, 保存并提交符合按钮将会进入, 修改符合状态
              if (submitFlag) {
                // if (this.callInitStatus) {
                //   // 发送邮件并自动通过审核. 且状态改为显示
                //   await sendReviewAnnouncement(response.data.id).then(response2 => {
                //     this.msgSuccess(this.$t(response2.msg))
                //     this.closeForm()
                //   })
                // } else {
                await updateReviewStatus(response.data.id, '待复核').then(response2 => {
                  this.msgSuccess(this.$t(response2.msg))
                  this.updateEmailTip()
                })
                // }
              } else {
                // 仅保存
                this.msgSuccess(this.$t('保存成功'))
                this.updateEmailTip()
              }
            } else {
              this.msgError(response.msg)
              this.updateEmailTip()
            }
          })
        }
      })
    },
    updateEmailTip() {
      this.loading = false
      var _this = this
      var flag = false
      _this.form.lpBaseList && _this.form.lpBaseList.forEach(item => {
        if (_this.isEmpty(item.lpEmail) && !flag) {
          flag = true
        }
      })
      if (flag) {
        this.$confirm(this.$t('是否需要维护邮箱?'), this.$t('提示'), {
          confirmButtonText: this.$t('我填好了'),
          cancelButtonText: this.$t('继续维护'),
          type: 'info'
        }).then(() => {
          _this.closeForm()
        }).catch(() => {
          // 如果在项目外. 公示公告页面. 就刷新一下list页面
          if (_this.isEmpty(_this.$route.query.id)) {
            _this.$parent.$parent.getList()
          }
        })
      } else {
        this.closeForm()
      }
    },
    // 根据公告类型获取对应的模板
    changeType(type) {
      this.autoUseTemplate(type)
      this.form.lpBaseList = []
      // 根据选择的公告类型 禁用关键字插入按钮
      this.optionalKeywordsMethod()
      // 加载开始
      this.displayNone = { period: false, fundScale: false, callPeriod: false, callProp: false, callMoney: false }
      if (type !== null && type !== '' && type !== undefined) {
        this.loading = true
        getLpAnnouncementTemplate(type).then(response => {
          const data = response.data
          const fundId = this.form.fundId
          if (data.selected === 'FPTZ') {
            this.displayNone = { period: true, fundScale: false, callProp: false, callMoney: false }
            // 获取分配批次
            if (fundId !== '' && fundId !== undefined) {
              this.getFundFpMain({ fundId: fundId })
            }
          } else if (data.selected === 'JKTZ') {
            this.displayNone = { period: false, fundScale: true, callPeriod: true, callProp: true, callMoney: true }
            // 加载Call款期次
            this.getTheCallPeriodByFundId()
            // 获取缴款相应金额
            if (fundId !== '' && fundId !== undefined) {
              this.getFundPaymentAmount({ fundId: fundId })
              this.callCalculation()
            }
          }
          this.form.title = response.data.title
          this.$refs.editorText.setContent(response.data.context)
          this.form.context = response.data.context
          this.$forceUpdate()
          this.loading = false
        })
      }
    },
    // 关键字能选那些
    optionalKeywordsMethod() {
      var keywordTemp = []
      var temp = ''
      this.keywordList.forEach(item => {
        if (this.templateType === 'JKTZ' && this.fpKey.includes(item.dictValue)) {
          temp += item.dictValue
        } else if (this.templateType === 'FPTZ' && this.callKey.includes(item.dictValue)) {
          temp += item.dictValue
        } else if (this.templateType !== 'JKTZ' && this.templateType !== 'FPTZ' && this.defaultOptionalKey.includes(item.dictValue)) {
          temp += item.dictValue
        } else {
          keywordTemp.push(item.dictValue)
        }
      })
      if (temp === '1') {
        console.log(temp)
      }
      this.optionalKeywords = keywordTemp
    },
    // 获取分配批次
    getFundFpMain(data) {
      this.allocationPeriodDict = []
      this.loading = true
      listFundFpMainAll(data).then(response => {
        response.data.forEach(item => {
          const data = {
            id: item.id,
            name: item.fpQc
          }
          this.allocationPeriodDict.push(data)
        })
        this.loading = false
      })
    },
    // 获取缴款金额
    getFundPaymentAmount(data) {
      this.loading = true
      listFundInvestorAll(data).then(response => {
        var number = 0
        response.data.forEach(item => {
          number += item.subscribedAmount
        })
        this.form.fundScale = number
        this.loading = false
      })
    },
    blurEvent(e, type) {
      this.isTitleSetKeWord = e !== undefined
      this.isSetKeyWordType = type
    },
    // 插入关键字
    addKeyWork(value) {
      if (this.isTitleSetKeWord) {
        if (this.form.title === undefined || this.form.title === null) {
          this.form.title = ''
        }
        if (this.isSetKeyWordType === 'title') {
          this.form.title += '【' + this.$t(value) + '】'
        }
      }
      if (this.isSetKeyWordType === 'context') {
        this.$refs.editorText.addEditorKeyWord('【' + this.$t(value) + '】')
      }
    },
    okPostUploadHook() {
      this.uploadLoading = true
    },
    querySearch(queryString, index, type, lpId) {
      if (this.isEmpty(queryString)) {
        listDealContacts({ businessId: this.form.lpBaseList[index].lpId }).then(response => {
          var restaurants = []
          response.rows && response.rows.forEach(item => {
            if (!this.isEmpty(item.email)) {
              restaurants.push({ email: '(' + item.contactsName + ')' + item.email, value: '(' + item.contactsName + ')' + item.email })
            }
          })
          this.$set(this.fileFormatArr, lpId, restaurants)
          this.$forceUpdate()
        })
      } else {
        if (type === 'lpEmail') {
          this.$set(this.form.lpBaseList[index], 'emailValue', queryString)
        }
        if (type === 'lpEmailCc') {
          this.$set(this.form.lpBaseList[index], 'emailCcValue', queryString)
        }
      }
    },
    closeAllInput() {
      if (this.lpEmailVisible) {
        Object.keys(this.lpEmailVisible).forEach(item => {
          this.lpEmailVisible[item] = false
        })
      }
      if (this.lpEmailCcVisible) {
        Object.keys(this.lpEmailCcVisible).forEach(item => {
          this.lpEmailCcVisible[item] = false
        })
      }
    },
    // 格式化邮箱显示
    splitEmail(row, field) {
      if (this.isEmpty(row[field])) {
        row[field] = ''
        return ''
      }
      return row[field].split(';')
    },
    handleClose(row, index, tag, type) {
      if (type === 'to') {
        var lpEmail = row.lpEmail.split(';')
        lpEmail.splice(lpEmail.indexOf(tag), 1)
        if (lpEmail.length === 0) {
          this.$set(this.form.lpBaseList[index], 'lpEmail', undefined)
        } else {
          this.$set(this.form.lpBaseList[index], 'lpEmail', lpEmail.join(';'))
        }
      }
      if (type === 'cc') {
        var lpEmailCc = row.lpEmailCc.split(';')
        lpEmailCc.splice(lpEmailCc.indexOf(tag), 1)
        this.form.lpBaseList[index].lpEmailCc = lpEmailCc.join(';')
      }
      this.$forceUpdate()
    },
    handleEmailConfirm(row, val) {
      if (val.target.value) {
        row.emailValue = val.target.value
      }
      setTimeout(() => {
        if (this.checkInvestEmail(row.emailValue)) {
          if (row.emailValue) {
            var lpEmailTemp = row.lpEmail.split(';')
            lpEmailTemp.push(row.emailValue)
            lpEmailTemp = lpEmailTemp.filter((item) => !!item)
            row.lpEmail = lpEmailTemp.join(';')
          }
        }
        row.emailValue = ''
        this.closeAllInput()
      }, 100)
    },
    handleEmailCcConfirm(row, val) {
      if (val.target.value) {
        row.emailCcValue = val.target.value
      }
      setTimeout(() => {
        if (this.checkInvestEmail(row.emailCcValue)) {
          if (row.emailCcValue) {
            var lpEmailTemp = row.lpEmailCc.split(';')
            lpEmailTemp.push(row.emailCcValue)
            lpEmailTemp = lpEmailTemp.filter((item) => !!item)
            row.lpEmailCc = lpEmailTemp.join(';')
          }
        }
        row.emailCcValue = ''
        this.closeAllInput()
      }, 100)
    },
    showEmailInput(row) {
      this.closeAllInput()
      this.$set(this.form.lpBaseList, 'emailValue', '')
      this.$set(this.lpEmailVisible, row.lpId, true)
    },
    showEmailCcInput(row) {
      this.closeAllInput()
      this.$set(this.form.lpBaseList, 'emailCcValue', '')
      this.$set(this.lpEmailCcVisible, row.lpId, true)
    },
    // 上传后附件回显
    appendData(data) {
      const file = {
        id: data.fileId === undefined ? data.id : data.fileId,
        name: data.fileName === undefined ? data.name : data.fileName
      }
      this.form.fileList.push(file)
      this.uploadLoading = false
    },
    // 预览附件
    onlinePreview(row) {
      var id = row.id
      if (id === null || id === undefined || id === '') {
        id = row.fileId
      }
      this.$refs.OnlinePreview.onlinePreviewFile(id)
    },
    // 删除附件
    delFile(row, index) {
      if (this.form.id !== undefined && this.form.id !== null) {
        this.uploadLoading = true
        delFile(row.id).then(response => {
          this.msgSuccess(this.$t(response.msg))
          this.uploadLoading = false
        })
      }
      this.form.fileList.splice(index, 1)
    },
    // 基金变化
    async dataChange(fundId) {
      console.log('基金变化')
      // 刷新类型下载
      await this.getLpTemplateSelect()
      // 获取模板类型
      this.autoUseTemplate(this.form.type)
      // 获取基金规模
      if (fundId !== '' && fundId !== undefined && (this.form.fundScale === undefined || this.form.fundScale === '' || this.form.fundScale !== null)) {
        this.getFundPaymentAmount({ fundId: fundId })
        // 加载所有基金出资人
        this.getFundInvestorList(fundId)
      }
      // 分配加载
      if (this.templateType === 'FPTZ') {
        this.getFundFpMain({ fundId: fundId })
      }
      // 如果为Call款通知  加载Call款下拉
      if (this.templateType === 'JKTZ') {
        // 获取根据基金ID 获取Call款期次下拉
        this.getTheCallPeriodByFundId()
        // 基金里打开
        if (this.callInitStatus) {
          console.log('基金内打开', this.form.type, this.form.callPeriod)
          this.$nextTick(() => {
            this.changeType(this.form.type)
            this.changeCallPeriod()
          })
        } else {
          console.log('基金外打开')
          // 切换基金时, 清空Call款的各个金额
          this.form.callPeriod = undefined
          this.changeCallPeriod()
        }
      }
    },
    // 计算Call款金额
    callCalculation() {
      if (this.form.fundScale !== undefined && this.form.fundScale !== '' && !isNaN(this.form.fundScale)) {
        this.form.callMoney = this.form.fundScale * (this.form.callProp / 100)
      }
      // 重新计算 出资人的Call款比例
      if (this.form.lpBaseList !== undefined && this.form.lpBaseList.length > 0 && this.templateType === 'JKTZ') {
        this.form.lpBaseList.forEach(item => {
          item.callMoney = item.subscribedAmount * (this.form.callProp / 100)
        })
      }
    },
    // 打开出资人列表
    openInvestList() {
      this.title = this.$t('出资人列表')
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.lpInvestorOpen = true
          this.$nextTick(() => {
            this.$refs.listOfFundersInTheFund.topPeriod = this.form.callPeriod
            this.$refs.listOfFundersInTheFund.fundId = this.form.fundId
            if (this.form.lpBaseList === undefined) {
              this.form.lpBaseList = []
            }
            this.$refs.listOfFundersInTheFund.multiSelectOperation = this.form.lpBaseList
            this.$refs.listOfFundersInTheFund.queryParams.investorType = 'investor'
            this.$refs.listOfFundersInTheFund.getList()
          })
        } else {
          this.locationError(document)
        }
      })
    },
    // 选中的lp
    choiceBaseList(data) {
      if (data !== null && data !== undefined) {
        data.forEach(item => {
          const object = this.form.lpBaseList.find(obj => obj.lpId === item.lpId)
          if (!object) {
            this.form.lpBaseList.push({
              lpId: item.lpId,
              lpType: item.investorType,
              userName: item.userName,
              lpPhone: item.lpPhone,
              lpEmail: item.lpEmail,
              lpEmailCc: item.lpEmailCc,
              level: item.level,
              subscribedAmount: item.subscribedAmount
            })
          }
        })

        // call款
        if (this.templateType === 'JKTZ') {
          this.form.lpBaseList.forEach((item, index) => {
            const object = data.find(obj => obj.lpId === item.lpId)
            if (object) {
              if (item.callMoney === undefined || item.callMoney === null) {
                this.$set(this.form.lpBaseList[index], 'callMoney', object.thisCallMoney)
                this.$set(this.form.lpBaseList[index], 'callTime', object.callDate)
              }
            }
          })
        }
      }
      this.lpInvestorOpen = false
    },
    // 预览转义后的信息
    viewInvestorInfo(row) {
      if (this.isEmpty(this.form.fundId)) {
        this.msgError('请先选择基金')
      } else {
        this.viewInvestorInfoOpen = true
        this.viewInvestorInfoLoading = true
        this.viewHtmlInfo = ''
        viewInvestorInfo(this.form).then(response => {
          response.data && response.data.lpBaseList && response.data.lpBaseList.forEach(item => {
            if (item.lpId === row.lpId) {
              this.viewHtmlInfo = item.remark
            }
            this.viewInvestorInfoLoading = false
          })
        })
      }
    },
    // 删除选中的lp
    delLpBase(row, index) {
      if (row.id !== undefined && row.id !== null) {
        this.LpBulletinInvestorLoading = true
        delLpBulletinInvestor(row.id).then(response => {
          this.msgSuccess(this.$t(response.msg))
          this.LpBulletinInvestorLoading = false
        })
      }
      this.form.lpBaseList.splice(index, 1)
    },
    /** 添加附件 */
    addFiles(row, index) {
      this.currentInvestId = row.lpId
      if (!(this.form.lpBaseList[index].fileList instanceof Array)) {
        this.$set(this.form.lpBaseList[index], 'fileList', [])
      }
      this.investorFileList = this.form.lpBaseList[index].fileList
      this.addFilesOpen = true
    },
    // Call款点击后生成当前出资人专属Call款文档
    generateExclDoc() {
      var _this = this
      this.LpBulletinInvestorText = ''
      this.$confirm(this.$t('是否自动生成(刷新)出资人对应的Call款文档, 这将会清空您现有的文件, 是否继续?'), this.$t('提示'), {
        confirmButtonText: this.$t('继续'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(() => {
        var topParentList = _this.$parent.$parent
        if (topParentList.generateCallNotice === undefined) {
          topParentList = _this.$parent.$parent.$parent.$parent
        }
        var parentFundCallMoneyDetail = topParentList.fundCallMoneyDetailList
        if (parentFundCallMoneyDetail && parentFundCallMoneyDetail.length <= 0) {
          parentFundCallMoneyDetail = _this.$parent.$parent.form.fundCallMoneyDetailList
        }
        var count = 0
        _this.LpBulletinInvestorLoading = parentFundCallMoneyDetail.length > 0
        parentFundCallMoneyDetail && parentFundCallMoneyDetail.forEach(item => {
          _this.form.lpBaseList && _this.form.lpBaseList.forEach((sub, index) => {
            if (item.investId === sub.lpId) {
              topParentList.generateCallNoticeByFundCall(item, data => {
                _this.$set(_this.form.lpBaseList[index], 'fileList', [{ id: data.id, name: data.name, businessId: _this.$route.query.id }])
                _this.$forceUpdate()
                count++
                this.LpBulletinInvestorText = this.$t('正在转换文件') + ' (' + _this.form.lpBaseList.length + '/' + (_this.form.lpBaseList.length - count) + ')'
                if (count === _this.form.lpBaseList.length) {
                  _this.LpBulletinInvestorLoading = false
                  this.LpBulletinInvestorText = ''
                }
              })
            }
          })
        })
      }).catch(() => {
      })
    },
    // 生成分配文档
    generateFpExclDoc() {
      var _this = this
      this.LpBulletinInvestorText = ''
      this.$confirm(this.$t('是否自动生成(刷新)出资人对应的文档, 这将会清空您现有的文件, 是否继续?'), this.$t('提示'), {
        confirmButtonText: this.$t('继续'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(() => {
        // 区分从List打开还是form打开
        var topParentThis = _this.$parent.$parent
        if (topParentThis.getList === undefined) {
          topParentThis = _this.$parent.$parent.$parent.$parent
        }

        // list
        var parentFundFpDetailsList = []
        topParentThis && topParentThis.fundFpMainList.forEach(item => {
          if (item.id === this.form.period) {
            parentFundFpDetailsList = item.fundFpDetailsList
          }
        })

        // form
        if (parentFundFpDetailsList && parentFundFpDetailsList.length <= 0) {
          parentFundFpDetailsList = _this.$parent.$parent.form.fundFpDetailsList
        }
        var count = 0
        _this.LpBulletinInvestorLoading = parentFundFpDetailsList.length > 0
        parentFundFpDetailsList && parentFundFpDetailsList.forEach(item => {
          _this.form.lpBaseList && _this.form.lpBaseList.forEach((sub, index) => {
            if (item.customerId === sub.lpId) {
              topParentThis.generateFpNoticeByFundFp(item, data => {
                _this.$set(_this.form.lpBaseList[index], 'fileList', [{ id: data.id, name: data.name, businessId: _this.$route.query.id }])
                _this.$forceUpdate()
                count++
                this.LpBulletinInvestorText = this.$t('正在转换文件') + ' (' + _this.form.lpBaseList.length + '/' + (_this.form.lpBaseList.length - count) + ')'
                if (count === _this.form.lpBaseList.length) {
                  _this.LpBulletinInvestorLoading = false
                  this.LpBulletinInvestorText = ''
                }
              })
            }
          })
        })
      }).catch(() => {
      })
    },
    onSuccess(response, file, fileList) {
      console.log(response, file, fileList)
      const invest = this.form.lpBaseList.find(obj => obj.lpId === this.currentInvestId)
      response.data && response.data.forEach(item => {
        invest.fileList.push({ id: item.fileId, name: item.fileName })
      })
      this.fileLoading = false
    },
    onError(error, file, fileList) {
      this.msgError(this.$t('上传失败'))
      console.log(error, file, fileList)
    },
    onProgress(event, file, fileList) {
      this.fileLoading = true
      console.log(event, file, fileList)
    },
    delRow(index) {
      const invest = this.form.lpBaseList.find(obj => obj.lpId === this.currentInvestId)
      invest.fileList.splice(index, 1)
    },
    // 关闭出资人列表选择页面
    lpBaseClean() {
      this.lpInvestorOpen = false
    },
    // 获取根据基金ID 获取Call款期次
    getTheCallPeriodByFundId() {
      if (this.form.fundId) {
        listFundCallMoneyAll({ fundId: this.form.fundId }).then(response => {
          this.callPeriodOptions = response.data
        })
      }
    },
    // Call款期次
    changeCallPeriod() {
      if (this.form.callPeriod) {
        console.log('changeCallPeriod -> val', this.form.callPeriod)
        this.loading = true
        this.LpBulletinInvestorLoading = true
        getFundCallMoney(this.form.callPeriod).then(response => {
          const data = response.data
          this.form.callMoney = data.callMoney
          this.form.callProp = data.thisCallProportion
          // 将Call款出资人是 LP或GP的添加到 公告出资人列表
          console.log('data.fundCallMoneyDetailList => ', data.fundCallMoneyDetailList)
          if (data.fundCallMoneyDetailList) {
            // 清空出资人
            this.form.lpBaseList = []
            data.fundCallMoneyDetailList.forEach(item => {
              // 从Call款期次子表的出资人里取出this.callFunder里的某个对应的出资人
              var obj = this.callFunder.find((obj) => {
                return obj.customerId === item.investId
              })
              if (obj) {
                var lpRow = {
                  lpId: item.investId,
                  lpType: item.investType,
                  userName: item.investName,
                  lpEmail: obj.lpEmail,
                  lpEmailCc: obj.lpEmailCc,
                  lpPhone: obj.lpPhone,
                  level: obj.level,
                  subscribedAmount: item.payMoney,
                  callMoney: item.thisCallMoney,
                  callTime: response.data.callDate
                }
                this.form.lpBaseList.push(lpRow)
              }
            })
          }
          this.setLpEmail()
          this.LpBulletinInvestorLoading = false
          this.loading = false
        })
      } else {
        console.log('changeCallPeriod -> else', this.form)
        // 取消Call款期次 金额归零, 并清空出资人
        this.form.callMoney = 0
        this.form.callProp = 0
        this.form.lpBaseList = []
      }
    },
    // 选择分配其次后, 带出该期次下的出资人
    showFpInvestor(id) {
      if (id) {
        showFpInvestor(id).then(response => {
          // 清空出资人
          this.form.lpBaseList = []
          var temp = []
          response.data && response.data.forEach(item => {
            if (!temp.includes(item.id)) {
              var lpRow = {
                lpId: item.id,
                lpType: item.type,
                userName: item.name,
                lpEmail: item.email,
                lpPhone: item.phone,
                lpEmailCc: item.emailCc,
                level: item.level
              }
              this.form.lpBaseList.push(lpRow)
              temp.push(item.id)
            }
          })
        })
      }
    },
    // 上传的文件自动关联到出资人
    uploadAuto() {
      this.autoUploadOpen = true
      this.$nextTick(() => {
        this.$refs.autoUpload.init(this.form.fundId)
      })
    },
    // 关闭自动上传页面, 并给lp分配文件
    autoUploadFileEnd(fileList) {
      this.showLpList = false
      this.$nextTick(() => {
        this.showLpList = true
        this.form.lpBaseList.forEach(item => {
          item.fileList = []
          fileList.forEach(file => {
            if (file.lpId === item.lpId) {
              item.fileList.push(file)
            }
          })
        })
      })
    }
  }
}

</script>
<style lang="scss" scoped>
  /deep/.el-table--enable-row-transition .el-table__body td.el-table__cell {
    z-index: 2001;
    background-color: #ffffff;
  }
  /deep/.el-loading-mask{
    z-index: 2002;
  }
</style>
